using System.Linq;
using UnityEngine;

namespace MaterialUI
{
	public static class TransformExtension
	{
		public static void SetParentAndScale(this Transform transform, Transform parent, Vector3 localScale, bool worldPositionStays = false)
		{
			transform.SetParent(parent, worldPositionStays);
			transform.localScale = localScale;
		}

		public static Canvas GetRootCanvas(this Transform transform)
		{
			Canvas[] componentsInParent = transform.GetComponentsInParent<Canvas>();
			if (componentsInParent == null || componentsInParent.Length == 0)
			{
				return null;
			}
			return componentsInParent.Last();
		}
	}
}
